package view;

import domain.ATM;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.stage.StageStyle;


import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

public class CardReaderViewController implements ControlledStage, Initializable{

    private StageController myController;
    private ATM atm;

    @FXML
    private TextField cardNumber;
    @FXML
    private Button readCard;

    public void setStageController(StageController stageController) {
        this.myController = stageController;
    }


    public void initialize(URL location, ResourceBundle resources) {

    }

    public void goToMain(){
        myController.setStage(MainApp.mainViewID);
    }


    @FXML
    private void cardReaderAction(ActionEvent event) throws IOException {
        atm = myController.getAtm();
        System.out.println("You clicked the Button " + readCard.getId());
        atm.setCurAccount(atm.makeNewIdentification(cardNumber.getText()));
        if(atm.getCurAccount() != null){
            myController.setAtm(atm);

            myController.loadStage(MainApp.passwordViewID, MainApp.passwordViewRes, StageStyle.DECORATED);
            myController.setStage(MainApp.passwordViewID,MainApp.cardReaderViewID);
        }else{
            atm.setCurMessageType("0");
            myController.setAtm(atm);

            myController.loadStage(MainApp.messageViewID,MainApp.messageViewRes);
            myController.setStage(MainApp.messageViewID);
        }
        cardNumber.clear();

    }
}